import axios from "axios";
import auth from "@/utils/auth";
import router from "@/router";

const BASE_URL = "http://localhost:6520";

axios.interceptors.request.use(config => {

    config.baseURL = BASE_URL;
    config.headers.Authorization = auth.token;

    return config;
})

axios.interceptors.response.use(response => {
    console.log(response)
    if(response.data.code === 403){
        auth.clearUserAndToken()
        router.push('/login').then(err => {
            console.log(err)
        })
    }

    return response
})

export default axios
